import java.util.Arrays;

/**
 * 2578. 最小和分割
 */
public class No2578 {
    public int splitNum(int num) {
        String str = num + "";
        int n = str.length(), mid = n / 2;

        char[] charArray = str.toCharArray();
        Arrays.sort(charArray);

        boolean single = n % 2 == 1;
        char[] chars1 = new char[single ? mid + 1 : mid];
        char[] chars2 = new char[mid];
        for (int i = 0; i < mid; i++) {
            chars1[i] = charArray[i * 2];
            chars2[i] = charArray[i * 2 + 1];
        }
        if (single) chars1[mid] = charArray[n - 1];

        String s1 = new String(chars1);
        String s2 = new String(chars2);
        return Integer.parseInt(s1) + Integer.parseInt(s2);
    }
}
